Column

Chart A

This bar plot shows the number of orders placed in each aisle.

Column

Chart B

This box plot shows the distribution of days since prior order by department.

Chart C

This line plot shows the number of orders placed throughout the day by department.

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```

```{r}
data("instacart")

instacart1 = 
  instacart %>% 
  select(order_id, product_id, user_id, order_dow, order_hour_of_day, days_since_prior_order, product_name, aisle_id, aisle, department_id, department) %>% 
  sample_n(5000)
  
```


Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

This bar plot shows the number of orders placed in each aisle.

```{r}
instacart1 %>% 
  count(aisle) %>% 
  mutate(aisle = factor(aisle),
         aisle = fct_reorder(aisle, n)) %>% 
  plot_ly(
    x = ~aisle, y = ~n, color = ~aisle, type = "bar",
    colors = "viridis"
  )
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

This box plot shows the distribution of days since prior order by department.

```{r}
instacart1 %>% 
  mutate(department = factor(department),
         department = fct_reorder(department, days_since_prior_order)) %>% 
  plot_ly(
    x = ~department, y = ~days_since_prior_order, color = ~department, type = "box",
    colors = "viridis"
  )
```

### Chart C

This line plot shows the number of orders placed throughout the day by department. 

```{r}
instacart1 %>% 
  group_by(department) %>% 
  count(order_hour_of_day) %>% 
  plot_ly(
    x = ~order_hour_of_day, y = ~n, color = ~department, type = "scatter",
    mode = "lines", colors = "viridis"
  )
```